import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './permission'

//引入ECharts
const echarts = require('echarts');
//全局使用
Vue.prototype.$echarts = echarts;

//elementui引入
import Element from 'element-ui'
import "element-ui/lib/theme-chalk/index.css"

//axios引入
import axios from 'axios'


//elementui 使用
Vue.use(Element)


//在全局使用axios
Vue.prototype.$axios = axios;
//所有发出去的请求都会加上该前缀
axios.defaults.baseURL = "http://10.101.105.193:8081";
// axios.defaults.baseURL = "https://qjun.chaiyi.fun";

axios.defaults.withCredentials = true;


//请求前置拦截
axios.interceptors.request.use(config => {
    console.log(config);
    return config; //暂且不做处理，可以拦截到后加http头之类的
})

//请求后置拦截
axios.interceptors.response.use(response => {
    let res = response.data;
    // console.log(response)
    if (res.code == 200) {
        return res;
    } else if(res.code>=300&res.code<400) {
        const warning = res.msg;
        Element.Message({
            message: warning,
            type: 'warning'
        });
        return Promise.reject(res.msg);
    }else if(res.code == 499){
        const errMsg = res.msg;
        console.log(res)
        Element.Message.error(errMsg);
        router.push("/login")
        return Promise.reject(res.msg);
    }
    else{
        const errMsg = res.msg;
        Element.Message.error(errMsg);
        return Promise.reject(res.msg);
    }
})


Vue.config.productionTip = false;

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')